package com.kun.context;

import com.kun.resp.MemberLoginResp;
import org.hibernate.validator.internal.util.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @className: LoginMemberContext
 * @Description: 通过ThreadLocal存储用户登录信息
 * @author: kunkun
 * @date: 2025/7/26 17:48
 */
public class LoginMemberContext {

    private static Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);

    static ThreadLocal<MemberLoginResp> member = new ThreadLocal<>();

    public static MemberLoginResp getMember(){
        return member.get();
    }

    public static void setMember(MemberLoginResp member){
        LoginMemberContext.member.set(member);
    }

    public static Long getId(){
        try {
            return member.get().getId();
        } catch (Exception e) {
            LOG.error("获取登录会员信息异常",e);
            throw e;
        }
    }
}
